#!/bin/bash

:<<!
	脚本最终优化备注：
	1.软件安装目录尽量修改为：/usr/local
	2.软件备份文件备份两份：当前备份文件目录 + /opt/backup目录
	3.菜单结构优化
	4.提示文字颜色修改
	5.一键安装redis
	6.一键配置/卸载redis
	7.一键安装/卸载/配置 消息队列
	8.一键添加定时任务
!

#脚本版本
sh_ver=1.0.8

deploy_path=/home
src_path=/home

error_flag=0;
reload_main_munu=0;

###########mysql备份设置##############
#备份路径
base_path=/opt
#mysql用户名
db_mysql_user=root
#mysql密码
db_mysql_password=12345
yearmonth=`date "+%Y%m"`
timestamp=`date "+%Y%m%d%H%M%S"`
###########mysql备份设置##############

#tomcat下载路径
tomcat_url=http://mirror.bit.edu.cn/apache/tomcat/tomcat-9/v9.0.14/bin/apache-tomcat-9.0.14.tar.gz
#tomcat版本
tomcat_version=9.0.14
#tomcat包名
tomcat_package=apache-tomcat-9.0.14.tar.gz
#tomcat文件名
tomcat_name=apache-tomcat-9.0.14

#nginx下载路径
nginx_url=http://nginx.org/download/nginx-1.15.9.tar.gz
#nginx包名
nginx_package=nginx-1.15.9.tar.gz
#nginx文件名
nginx_name=nginx-1.15.9

########SSR脚本下载路径########
ssr_simple_url=https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/ssr.sh
ssr_simple_backup_url=https://softs.fun/Bash/ssr.sh
ssr_multi_url=https://softs.fun/Bash/ssrmu.sh
ssr_multi_backup_url=https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/ssrmu.sh
ssr_bbr_url=https://github.com/teddysun/across/raw/master/bbr.sh
########SSR脚本下载路径########

#############mysql安装配置##################
mysql_pwd=123456
mysql_6_rpm=http://dev.mysql.com/get/mysql57-community-release-el6-8.noarch.rpm
mysql_6_rpm_name=mysql57-community-release-el6-8.noarch.rpm
mysql_7_rpm=http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
mysql_7_rpm_name=mysql57-community-release-el7-11.noarch.rpm
#############mysql安装配置##################


######字体颜色设置#########
Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m"
Yello_font_prefix="\033[33m" && Blue_font_prefix="\033[34m" && Pink_font_prefix="\033[35m"
######字体颜色设置#########



input_operate_type=">>选择主菜单功能序号(默认为0)：\c";
input_operate_type_sub=">>选择子菜单序号(默认为0)：\c";
input_port_num=">>输入需要开放的端口号(n:取消)：\c";
input_port_del=">>是否需要删除防火墙规则？y/n(默认n)：\c";
input_port_del_num=">>输入需要删除防火墙规则num：\c";
input_spring_boot=">>输入需要启动的spring boot项目文件路径加文件名：\c";
input_tomcat_status=">>是否现在启动tomcat？y/n(默认y)：\c";
input_tomcat_clear=">>是否清空tomcat的WebApps目录？y/n(默认y)：\c";
input_tomcat_flag=">>启动或停止tomcat_0:停止/1:启动_(默认1)：\c";
input_kill_port=">>强制杀掉此进程(0取消),输入进程ID：\c";

input_install_type=">>选择安装单用户版本或者多用户版本__0:单用户/1:多用户_(默认0)：\c";
input_backup_type=">>选择是否启用备用配置脚本？y/n(默认n)：\c";
input_bbrcheck_type=">>是否验证BBR已安装成功？y/n(默认y)：\c";
input_uninstall_type=">>确定卸载mysql？y/n(默认y)：\c";
input_open_mysql_flag=">>启动或停止mysql_0:启动/1:停止/2:重启_(默认2)：\c";
input_mysql_now_pwd=">>输入当前mysql密码：\c";
input_mysql_new_pwd=">>输入修改后的mysql密码：\c";

input_init_menu=">>是否重新加载主菜单？y/n(默认n)：\c";
input_database_name=">>输入需要备份的数据库名称：\c";
input_database_download=">>是否下载备份的数据库（y/n）：\c";

deploy_project_alias=">>输入项目名称：\c";
service_start_flag=">>需要启动应用服务吗？y/n(默认y)：\c";
service_stop_flag=">>需要关闭应用服务吗？y/n(默认y)：\c";
input_sql_name=">>输入待执行的sql脚本名称(不需要输入后缀)：\c";
input_sql_insert_flag=">>是否是数据库导入？y/n(默认n)：\c";
input_nginx_start_flag=">>启动或停止nginx__0:启动/1:停止_(默认0)：\c";
input_nginx_conf=">>确认替换nginx配置文件？y/n(默认y)：\c";
input_tomcat_conf=">>确认替换server.xml配置文件？y/n(默认y)：\c";
input_check_uninstall_tomcat=">>确认卸载tomcat？y/n(默认y)：\c";
input_check_install_tomcat=">>确认安装tomcat？y/n(默认y)：\c";

input_check_install_nginx=">>确认安装nginx？y/n(默认y)：\c";
input_check_install_nginx_ssl=">>确认安装SSL模块？y/n(默认y)：\c";
input_check_uninstall_nginx=">>确认卸载nginx？y/n(默认y)：\c";
input_check_install_mysql=">>确认安装mysql？y/n(默认y)：\c";
input_check_install_jdk=">>确认安装jdk？y/n(默认y)：\c";


#查看当前脚本配置
echoNowConfig(){
	echo -e "${Red_font_prefix}-1: 返回上级${Font_color_suffix}"
	 echo -e "${Green_font_prefix}脚本版本 :${Font_color_suffix} $sh_ver"
	 echo -e "${Green_font_prefix}项目部署路径 :${Font_color_suffix} $deploy_path"
	 echo -e "${Green_font_prefix}一键部署项目、执行脚本上传路径 :${Font_color_suffix} $src_path"
	 echo -e "${Green_font_prefix}mysql备份路径 :${Font_color_suffix} $base_path"
	 echo -e "${Green_font_prefix}mysql用户名:${Font_color_suffix} $db_mysql_user"
	 echo -e "${Green_font_prefix}mysql密码 :${Font_color_suffix} $db_mysql_password"
	 echo -e "${Green_font_prefix}tomcat下载路径 :${Font_color_suffix} $tomcat_url"
	 echo -e "${Green_font_prefix}tomcat版本 :${Font_color_suffix} $tomcat_version"
	 echo -e "${Green_font_prefix}tomcat包名 :${Font_color_suffix} $tomcat_package"
	 echo -e "${Green_font_prefix}tomcat文件名 :${Font_color_suffix} $tomcat_name"
	 
	 echo -e "${Green_font_prefix}nginx下载路径 :${Font_color_suffix} $nginx_url"
	 echo -e "${Green_font_prefix}nginx包名 :${Font_color_suffix} $nginx_package"
	 echo -e "${Green_font_prefix}nginx文件名 :${Font_color_suffix} $nginx_name"
	 
	 echo -e "${Green_font_prefix}ssr单用户脚本路径 :${Font_color_suffix} $ssr_simple_url"
	 echo -e "${Green_font_prefix}ssr单用户脚本备用路径 :${Font_color_suffix} $ssr_simple_backup_url"
	 echo -e "${Green_font_prefix}ssr多用户脚本路径 :${Font_color_suffix} $ssr_multi_url"
	 echo -e "${Green_font_prefix}ssr多用户脚本备用路径 :${Font_color_suffix} $ssr_multi_backup_url"
	 echo -e "${Green_font_prefix}bbr加速脚本路径:${Font_color_suffix} $ssr_bbr_url"
	 
	 echo -e "${Green_font_prefix}mysql安装结束默认密码 :${Font_color_suffix} $mysql_pwd"
	 echo -e "${Green_font_prefix}Centos6安装  mysql下载路径 :${Font_color_suffix} $mysql_6_rpm"
	 echo -e "${Green_font_prefix}Centos6安装  mysql文件名 :${Font_color_suffix} $mysql_6_rpm_name"
	 echo -e "${Green_font_prefix}Centos7安装  mysql下载路径  :${Font_color_suffix} $mysql_7_rpm"
	 echo -e "${Green_font_prefix}Centos7安装  mysql文件名:${Font_color_suffix} $mysql_7_rpm_name"
}

#输出菜单信息
printInfo(){
	 echo -e "${Pink_font_prefix}========Centos便携式脚本$sh_ver---Powered By lvjinhui=====${Font_color_suffix}"
	 echo -e "${Red_font_prefix}-1: 退出${Font_color_suffix}"
	 echo -e "${Green_font_prefix}0 :${Font_color_suffix} 查看服务器信息"
	 echo -e "${Green_font_prefix}1 :${Font_color_suffix} ${Yello_font_prefix}初始化项目部署目录${Font_color_suffix}"
	 echo -e "${Green_font_prefix}2 :${Font_color_suffix} ${Yello_font_prefix}一键部署项目${Font_color_suffix}"
	 echo -e "${Green_font_prefix}3 :${Font_color_suffix} ${Yello_font_prefix}一键备份项目/文件 ${Font_color_suffix}"
	 echo -e "${Green_font_prefix}4 :${Font_color_suffix} ${Yello_font_prefix}一键恢复项目/文件 ${Font_color_suffix}"
	 echo -e "${Green_font_prefix}5 :${Font_color_suffix} (预留:一键修改tomcat部署路径) "
	 echo -e "${Green_font_prefix}6 :${Font_color_suffix} 一键卸载nginx " #测试完毕
	 echo -e "${Green_font_prefix}7 :${Font_color_suffix} (预留 一键启用/关闭mysql公网访问) "
	 echo -e "${Green_font_prefix}8 :${Font_color_suffix} (预留) "
	 echo -e "${Green_font_prefix}9 :${Font_color_suffix} 查看脚本配置信息 "
	 echo -e "${Blue_font_prefix}————————————————————————————————————————${Font_color_suffix}"
	 echo -e "${Green_font_prefix}10 :${Font_color_suffix} ${Yello_font_prefix}yum一键安装JDK1.8${Font_color_suffix}"   #测试完毕
	 echo -e "${Green_font_prefix}11 :${Font_color_suffix} yum安装RZ文件上传工具 上传指令：rz -y 下载指令: sz "   #测试完毕
	 echo -e "${Blue_font_prefix}————————————————————————————————————————${Font_color_suffix}"
	 echo -e "${Green_font_prefix}12 :${Font_color_suffix} yum一键安装zlib,pcre,gc++库"   #测试完毕
	 echo -e "${Green_font_prefix}13 :${Font_color_suffix} yum安装weget"   #测试完毕
	 echo -e "${Green_font_prefix}14 :${Font_color_suffix} yum安装zip unzip"   #测试完毕
	 echo -e "${Blue_font_prefix}————————————————————————————————————————${Font_color_suffix}"
	 echo -e "${Green_font_prefix}15 :${Font_color_suffix} ${Yello_font_prefix}一键安装nginx 版本:$nginx_name 配置文件:/usr/local/nginx/conf/nginx.conf${Font_color_suffix}"  #测试完毕
	 echo -e "${Green_font_prefix}16 :${Font_color_suffix} 启动/关闭nginx"   #测试完毕
	 echo -e "${Green_font_prefix}17 :${Font_color_suffix} 一键替换nginx配置文件"  #测试完毕
	 echo -e "${Blue_font_prefix}————————————————————————————————————————${Font_color_suffix}"
	 echo -e "${Green_font_prefix}18 :${Font_color_suffix} ${Yello_font_prefix}开放端口${Font_color_suffix}"  #测试完毕
	 echo -e "${Green_font_prefix}19 :${Font_color_suffix} 启动Spring Boot项目"   #未测试===================
	 echo -e "${Blue_font_prefix}————————————————————————————————————————${Font_color_suffix}" 
	 echo -e "${Green_font_prefix}20 :${Font_color_suffix} ${Yello_font_prefix}一键安装tomcat$tomcat_version${Font_color_suffix}"  #测试完毕  
	 echo -e "${Green_font_prefix}21 :${Font_color_suffix} ${Red_font_prefix}启动或停止tomcat$tomcat_version${Font_color_suffix}"  #测试完毕
	 echo -e "${Green_font_prefix}22 :${Font_color_suffix} 查看tomcat运行状态以及强制关闭" #测试完毕
	 echo -e "${Green_font_prefix}23 :${Font_color_suffix} 查看tomcat$tomcat_version日志"  #测试完毕
	 echo -e "${Green_font_prefix}24 :${Font_color_suffix} 一键卸载tomcat$tomcat_version"  #测试完毕
	 echo -e "${Green_font_prefix}25 :${Font_color_suffix} 一键替换server.xml配置文件"     #测试完毕
	 echo -e "${Blue_font_prefix}————————————————————————————————————————${Font_color_suffix}"
	 echo -e "${Green_font_prefix}26 :${Font_color_suffix} 配置中文语言环境"  #测试完毕
	 echo -e "${Green_font_prefix}27 :${Font_color_suffix} (预留)"
	 echo -e "${Blue_font_prefix}————————————————————————————————————————${Font_color_suffix}"
	 echo -e "${Green_font_prefix}28 :${Font_color_suffix} Centos6搭建SSR 启动脚本:(bash ssrmu.sh/bash ssr.sh)"   #测试完毕
	 echo -e "${Green_font_prefix}29 :${Font_color_suffix} 安装谷歌BBR加速(需要重启服务器)"   #测试完毕
	 echo -e "${Blue_font_prefix}————————————————————————————————————————${Font_color_suffix}"
	 echo -e "${Green_font_prefix}30 :${Font_color_suffix} ${Yello_font_prefix}一键安装mysql 5.7${Font_color_suffix}" #测试完毕
	 echo -e "${Green_font_prefix}31 :${Font_color_suffix} 一键卸载mysql 5.7"  #测试完毕
	 echo -e "${Green_font_prefix}32 :${Font_color_suffix} ${Red_font_prefix}启动或停止mysql 5.7${Font_color_suffix}" #测试完毕
	 echo -e "${Green_font_prefix}33 :${Font_color_suffix} 修改mysql 5.7密码" #测试完毕
	 echo -e "${Green_font_prefix}34 :${Font_color_suffix} ${Yello_font_prefix}一键备份mysql数据库(支持备份完下载)${Font_color_suffix}"  #测试完毕
	 echo -e "${Green_font_prefix}35 :${Font_color_suffix} ${Yello_font_prefix}一键执行mysql脚本 （支持数据库导入）${Font_color_suffix}" #测试完毕
	 echo -e "${Pink_font_prefix}========Centos便携式脚本$sh_ver---Powered By lvjinhui=====${Font_color_suffix}"
}

printInfoSub(){
	 echo -e "${Green_font_prefix}0 :${Font_color_suffix} 内存，进程和分页等的简要信息"
	 echo -e "${Green_font_prefix}1 :${Font_color_suffix} CPU统计信息，设备和分区的输入/输出统计信息"
	 echo -e "${Green_font_prefix}2 :${Font_color_suffix} 系统时间-系统运行时间-已登录用户的数量-过去1分钟、5分钟、15分钟平均负载量"
	 echo -e "${Green_font_prefix}3 :${Font_color_suffix} 当前连接用户"
	 echo -e "${Green_font_prefix}4 :${Font_color_suffix} 最近登陆信息"
	 echo -e "${Green_font_prefix}5 :${Font_color_suffix} 硬盘及内存使用量"
	 echo -e "${Green_font_prefix}6 :${Font_color_suffix} 内存溢出情况"
	 echo -e "${Green_font_prefix}7 :${Font_color_suffix} 利用率及较多的进程"
	 echo -e "${Green_font_prefix}8 :${Font_color_suffix} 列出当前socket详细信息"
	 echo -e "${Green_font_prefix}9 :${Font_color_suffix} 列出当前所有进程"
}

#读取输入信息
inputInfo() {
	echo -e $1
	read -e temp
}
#安装nginx
installNginx(){
	cd /nginx/
	echo -e "${Green_font_prefix}开始下载$nginx_name...${Font_color_suffix}"
	wget $nginx_url
	echo -e "${Green_font_prefix}开始解压$nginx_name...${Font_color_suffix}"
	tar -zxvf $nginx_package
	echo -e "${Green_font_prefix}开始编译$nginx_name...${Font_color_suffix}"
	cd /nginx/$nginx_name
	#是否安装SSL模块
	inputInfo $input_check_install_nginx_ssl;
	check_install_nginx_ssl=$temp;
	if [ -z $check_install_nginx_ssl ];then
		check_install_nginx_ssl="y"
	fi
	
	if [ $check_install_nginx_ssl == "y" ];then
		yum install -y openssl*
		yum -y install ncurses-devel
		./configure --prefix=/usr/local/nginx --with-http_ssl_module
		echo -e "${Green_font_prefix}ssl模块安装完成...${Font_color_suffix}"
	else
		./configure 
		echo -e "${Green_font_prefix}取消ssl模块安装...${Font_color_suffix}"
	fi
	
	make
	sudo make install
	if [ $? -eq 0 ]; then
		echo -e "${Green_font_prefix}$nginx_name安装成功!${Font_color_suffix}"
		cd /
		rm /nginx -rf
		echo -e "${Green_font_prefix}安装文件清理成功!${Font_color_suffix}"
	else
		echo -e "${Red_font_prefix}$nginx_name安装失败!${Font_color_suffix}"
	fi
}
#安装tomcat
installTomcat(){
	cd /tomcat$tomcat_version
	echo -e "${Green_font_prefix}开始下载tomcat$tomcat_version...${Font_color_suffix}"
	if [ ! -f "/tomcat$tomcat_version/$tomcat_package" ];then
	wget $tomcat_url
	else
	rm -f /tomcat$tomcat_version/$tomcat_package
	fi			
	echo -e "${Green_font_prefix}开始解压tomcat$tomcat_version...${Font_color_suffix}"
	tar -zxvf $tomcat_package
	echo -e "${Green_font_prefix}tomcat$tomcat_version安装完成,路径：/tomcat$tomcat_version/$tomcat_name${Font_color_suffix}"
	
	
	inputInfo $input_tomcat_clear;
	tomcat_clear=$temp;
	if [ -z $tomcat_clear ];then
		tomcat_clear="y"
	fi
	
	if [ $tomcat_clear == "y" ];then
		cd /tomcat$tomcat_version/$tomcat_name/webapps/
		rm * -rf
		echo -e "${Green_font_prefix}webapps清空完毕...${Font_color_suffix}"
	fi
	
	
	chmod -R 777 /tomcat$tomcat_version/$tomcat_name/
	
	inputInfo $input_tomcat_status;
	tomcat_status=$temp;
	if [ -z $tomcat_status ];then
		tomcat_status="y"
	fi
	if [ $tomcat_status == "y" ]; then
		cd /tomcat$tomcat_version/$tomcat_name/bin
		./startup.sh 
		echo -e "${Green_font_prefix}tomcat$tomcat_version已启动.${Font_color_suffix}"
	elif [ $tomcat_status == "n" ]; then
		echo -e "${Green_font_prefix}执行完毕.${Font_color_suffix}"
	else
		printN
	fi
}

#删除防火墙规则
delport(){
	inputInfo $input_port_del;
	port_del=$temp;
	if [ -z $port_del ];then
		port_del="n"
	fi
	if [ $port_del == "y" ];then 
		#删除规则
		inputInfo $input_port_del_num;
		port_del_num=$temp;
		if [ -z $port_del_num ];then
			port_del_num="n"
		fi
		iptables -D INPUT $port_del_num
		echo -e "${Green_font_prefix}规则$port_del_num删除成功 !${Font_color_suffix}"
		echo -e "${Green_font_prefix}当前已开放端口如下:${Font_color_suffix}"
		/sbin/iptables -L -n --line-number
	elif [ $port_del == "n" ];then 
		echo -e "${Green_font_prefix}取消删除防火墙规则...${Font_color_suffix}"
		echo -e "${Green_font_prefix}当前已开放端口如下:${Font_color_suffix}"
		/sbin/iptables -L -n --line-number	
	else 
		echo -e "${Red_font_prefix}没有这个选项！！！${Font_color_suffix}"
	fi
}

printN(){
	echo -e "${Red_font_prefix}没有这个选项！！！${Font_color_suffix}"
}

#初始化项目部署目录
initPath(){
	inputInfo $deploy_project_alias;
	project_alias=$temp;

	if [ -z $project_alias ]; then
	    printN
	else
		if [ ! -d "$deploy_path/backups/db/$project_alias" ]; then
			mkdir -p $deploy_path/backups/db/$project_alias
		fi
		if [ ! -d "$deploy_path/backups/deploy/$project_alias" ]; then
			mkdir -p $deploy_path/backups/deploy/$project_alias
		fi
		if [ ! -d "$deploy_path/backups/deploy/config/$project_alias" ]; then
			mkdir -p $deploy_path/backups/deploy/config/$project_alias
		fi
		if [ ! -d "$deploy_path/deploy/config/$project_alias" ]; then
			mkdir -p $deploy_path/deploy/config/$project_alias
		fi
		if [ ! -d "$deploy_path/deploy/$project_alias" ]; then
			mkdir -p $deploy_path/deploy/$project_alias
		fi
		if [ ! -d "$deploy_path/deploy/logs/$project_alias" ]; then
			mkdir -p $deploy_path/deploy/logs/$project_alias
		fi
		if [ ! -d "$deploy_path/file/$project_alias" ]; then
			mkdir -p $deploy_path/file/$project_alias
		fi
		echo -e "${Green_font_prefix}$project_alias目录树创建成功!!!${Font_color_suffix}"
  fi
}

#部署项目
deployProject(){
	echo -e "${Green_font_prefix}提示：部署前先将war/jar包上传到服务器的 $src_path 目录${Font_color_suffix}"
	deploy_project_type=">>输入部署类型war,jar(默认war)：\c";
	deploy_project_jar_name=">>jar文件名:\c";
	
	inputInfo $deploy_project_alias;
	project_alias=$temp;
	
	if [ -z $project_alias ]; then
		printN
	elif [ ! -d "$src_path/deploy/$project_alias" ]; then
	  echo -e "${Red_font_prefix}$src_path/deploy/$project_alias目录不存在!!!${Font_color_suffix}"
	else
		inputInfo $deploy_project_type;
		deploy_type=$temp;
		jar_name="";

		if [ "$deploy_type" = "jar" ]; then
		   inputInfo $deploy_project_jar_name;
		   jar_name=$temp;
		   if [ -z $jar_name ]; then
					printN
					error_flag=1;
			 else
			 		jar_name=${jar_name%'.jar'}
			 fi
		   if [ ! -f "$src_path/$jar_name.jar" ]; then
		   		echo -e "${Red_font_prefix}$src_path/$jar_name.jar文件不存在!!!${Font_color_suffix}"
		   		error_flag=1
		   fi
		else
		   if [ ! -f "$src_path/$project_alias.war" ]; then
		   		echo -e "${Red_font_prefix}$src_path/$project_alias.war文件不存在!!!${Font_color_suffix}"
		   		error_flag=1
		   fi
		fi
		
	 # 没有错误,则进行deploy操作
	 if [ $error_flag -eq 0 ]; then
   		inputInfo $service_stop_flag;
			service_stop=$temp;
			
			if [ -z $service_stop ]; then
				service_stop=y
			fi
			if [ $service_stop = y ]; then
				cd $tomcat_path/bin
				./shutdown.sh
			fi
			
			# 项目备份操作
			timestamp=`date "+%Y%m%d%H%M%S"`
			if [ ! -d "$deploy_path/deploy/$project_alias" ]; then
				echo -e "${Red_font_prefix}$deploy_path/deploy/$project_alias目录不存在!!!${Font_color_suffix}"
			elif [ "`ls -A $deploy_path/deploy/$project_alias`" = "" ]; then
				echo -e "${Green_font_prefix}$deploy_path/deploy/$project_alias目录为空,无需备份${Font_color_suffix}"
			else
			  cd $deploy_path/deploy/$project_alias
			  zip -rq $deploy_path/backups/deploy/$project_alias/$project_alias-$timestamp.zip *
			
				if [ "`ls -A $deploy_path/deploy/config/$project_alias`" = "" ]; then
					echo -e "${Red_font_prefix}$deploy_path/deploy/config/$project_alias目录为空,无需备份${Font_color_suffix}"
				else
					cd $deploy_path/deploy/config/$project_alias
			  	zip -rq $deploy_path/backups/deploy/config/$project_alias/$project_alias-config-$timestamp.zip *
				fi
			  echo -e "${Green_font_prefix}$project_alias-$timestamp.zip备份完成${Font_color_suffix}"
			fi
			
			if [ ! -d "$deploy_path/deploy/$project_alias" ]; then
			  mkdir -p $deploy_path/deploy/$project_alias
			fi
			
			if [ ! -d "$deploy_path/deploy/config/$project_alias" ]; then
			  mkdir -p $deploy_path/deploy/config/$project_alias
			fi
			#删除项目log
			if [ -d "$deploy_path/deploy/logs/$project_alias" ]; then
			   cd $deploy_path/deploy/logs/$project_alias
			   rm -rf *
			fi
			#发布
			if [ "$deploy_type" = "jar" ]; then
				 #jar方式发布
			   let pos=`echo "$jar_name" | awk -F '-' '{printf "%d", length($0)-length($NF)}'`
			   cd $deploy_path/deploy/$project_alias/WEB-INF/lib/
			   rm -f ${jar_name:0:$pos}*
			   echo -e "${Green_font_prefix}${jar_name:0:$pos}*.jar删除成功${Font_color_suffix}"
			   cp $src_path/$jar_name.jar $src_path/deploy/$project_alias/WEB-INF/lib/
			   echo -e "${Green_font_prefix}$jar_name.jar发布成功${Font_color_suffix}"
			   
			   inputInfo $service_start_flag;
				 service_start=$temp;
				
				 if [ -z $service_start ]; then
					 service_start=y
				 fi
				
				 if [ $service_start = y ]; then
					 cd /tomcat$tomcat_version/$tomcat_name/bin
					 ./startup.sh
				 fi
			else
				#war方式发布
				cd $deploy_path/deploy/$project_alias
				rm -rf *
			
				cd /home
				unzip -oq $src_path/$project_alias.war -d $deploy_path/deploy/$project_alias
			
				echo -e "${Green_font_prefix}$project_alias解压成功${Font_color_suffix}"
			
				if [ ! "`ls -A $deploy_path/deploy/config/$project_alias`" = "" ]; then
			   	cp -r $deploy_path/deploy/config/$project_alias/* $deploy_path/deploy/$project_alias/
			   	echo -e "${Green_font_prefix}$project_alias配置成功${Font_color_suffix}"
			  else
			  	echo -e "${Red_font_prefix}$project_alias配置目录为空,未正常配置!!!${Font_color_suffix}"
				fi
			
				inputInfo $service_start_flag;
				service_start=$temp;
				
				if [ -z $service_start ]; then
					service_start=y
				fi
				
				if [ $service_start = y ]; then
					cd /tomcat$tomcat_version/$tomcat_name/bin
					./startup.sh
				fi
			fi
    fi
	fi
}

#备份项目
backupProject(){
	echo -e "${Green_font_prefix}备份类型：1.项目 2.文件 3.配置${Font_color_suffix}"
 	back_type=">>请选择(默认1)：\c";
 	inputInfo $back_type;
	backup_type=$temp;
	
	if [ -z $backup_type ]; then
		backup_type=1
	fi
	error_flag=1;
	timestamp=`date "+%Y%m%d%H%M%S"`
	
	if [ $backup_type = 1 ]; then
		inputInfo $deploy_project_alias;
		project_alias=$temp;
		
		if [ -z $project_alias ]; then
				printN
				error_flag=0;
		elif [ ! -d "$deploy_path/deploy/$project_alias" ]; then
				echo -e "${Red_font_prefix}$deploy_path/deploy/$project_alias目录不存在${Font_color_suffix}"
				error_flag=0;
		elif [ "`ls -A $deploy_path/deploy/$project_alias`" = "" ]; then
				echo -e "${Red_font_prefix}$deploy_path/deploy/$project_alias目录为空${Font_color_suffix}"
				error_flag=0;
		else
		  cd $deploy_path/deploy/$project_alias
		  zip -rq $deploy_path/backups/deploy/$project_alias/$project_alias-$timestamp.zip *
		  echo -e "${Green_font_prefix}$project_alias-$timestamp.zip备份成功${Font_color_suffix}"
		
		  cd $deploy_path/deploy/config/$project_alias
		  zip -rq $deploy_path/backups/deploy/config/$project_alias/$project_alias-config-$timestamp.zip *
		
		  echo -e "${Green_font_prefix}$project_alias-config-$timestamp.zip配置备份成功${Font_color_suffix}"
		  error_flag=0;
		fi
	fi


	if [ $backup_type = 2 ]; then
	 	backup_file=">>请输入项目名(默认所有项目)：\c";
	 	inputInfo $backup_file;
		backup_project_alias=$temp;		
			
		if [ ! -d "$deploy_path/file" ]; then
				echo -e "${Red_font_prefix}$deploy_path/file目录不存在${Font_color_suffix}"
				error_flag=0;
		elif [ "`ls -A $deploy_path/file`" = "" ]; then
				echo -e "${Red_font_prefix}$deploy_path/file目录为空${Font_color_suffix}"
				error_flag=0;
		else
			if [ -z $backup_project_alias ]; then
				cd $deploy_path/file
			  zip -rq $deploy_path/backups/file/file-$timestamp.zip *
			  echo -e "${Green_font_prefix}file-$timestamp.zip备份成功${Font_color_suffix}"
			  error_flag=0;
			else
				if [ ! -d "$deploy_path/file/$backup_project_alias" ]; then
					echo -e "${Red_font_prefix}$deploy_path/file/$backup_project_alias目录不存在${Font_color_suffix}"
					error_flag=0;
				elif [ "`ls -A $deploy_path/file/$backup_project_alias`" = "" ]; then
					echo -e "${Red_font_prefix}$deploy_path/file/$backup_project_alias目录为空${Font_color_suffix}"
					error_flag=0;
				else
					cd $deploy_path/file/$backup_project_alias
				  zip -rq $deploy_path/backups/file/$backup_project_alias/file_$backup_project_alias-$timestamp.zip *
				  echo -e "${Green_font_prefix}file_$backup_project_alias-file-$timestamp.zip备份成功${Font_color_suffix}"
				  error_flag=0;
				fi
		  fi
		fi
	fi



	if [ $backup_type = 3 ]; then
		backup_config=">>请输入项目名(默认所有)：\c";
	 	inputInfo $backup_config;
		backup_config_alias=$temp;

		if [ -z $backup_config_alias ]; then
				if [ ! -d "$deploy_path/deploy/config" ]; then
					echo -e "${Red_font_prefix}$deploy_path/deploy/config目录不存在${Font_color_suffix}"
					error_flag=0;
				elif [ "`ls -A $deploy_path/deploy/config`" = "" ]; then
					echo -e "${Red_font_prefix}$deploy_path/deploy/config目录为空${Font_color_suffix}"
					error_flag=0;
				else
					cd $deploy_path/deploy/config
				  zip -rq $deploy_path/backups/deploy/config/config-$timestamp.zip *
				  echo -e "${Green_font_prefix}config-$timestamp.zip备份成功${Font_color_suffix}"
				  error_flag=0;
				fi
		else
				if [ ! -d "$deploy_path/deploy/config/$backup_config_alias" ]; then
					echo -e "${Red_font_prefix}$deploy_path/deploy/config/$backup_config_alias目录不存在${Font_color_suffix}"
					error_flag=0;
				elif [ "`ls -A $deploy_path/deploy/config/$backup_config_alias`" = "" ]; then
					echo -e "${Red_font_prefix}$deploy_path/deploy/config/$backup_config_alias目录为空${Font_color_suffix}"
					error_flag=0;
				else
					cd $deploy_path/deploy/config/$backup_config_alias
			  	zip -rq $deploy_path/backups/config/$backup_config_alias/config_$backup_config_alias-$timestamp.zip *
					echo -e "${Green_font_prefix}config_$backup_config_alias-config-$timestamp.zip备份成功${Font_color_suffix}"
			  	error_flag=0;
			  fi
		fi
	fi

	
	if [ $error_flag -eq 1 ]; then
		printN
	fi
}

#恢复项目
recoveryProject(){
	echo -e "${Green_font_prefix}恢复类型：1.项目 2.文件${Font_color_suffix}"
 	recover_project_alias=">>请输入恢复类型(默认为1):\c";
 	recover_index=">>请输入需要恢复的序号(默认为1):\c";
	
	inputInfo $recover_project_alias;
	recover_project_value=$temp;
	
	if [ -z $recover_project_value ]; then
		recover_project_value=1
	fi
	
	timestamp=`date "+%Y%m%d%H%M%S"`
	
	if [ $recover_project_value = 2 ]; then
		
		if [ ! -d "$deploy_path/backups/file" ]; then
		
		  echo -e "${Red_font_prefix}$deploy_path/backups/file目录不存在${Font_color_suffix}"
		  
		elif [ "`ls -A $deploy_path/backups/file`" = "" ]; then
		   echo -e "${Red_font_prefix}$deploy_path/backups/file目录为空${Font_color_suffix}"
		else
			inputInfo $deploy_project_alias;
	    project_alias=$temp;

			if [ -z $project_alias ]; then
				printN
			elif [ ! -d "$deploy_path/backups/file/$project_alias" ]; then
				echo -e "${Red_font_prefix}err:$deploy_path/backups/file/$project_alias目录不存在${Font_color_suffix}"
			elif [ "`ls -A $deploy_path/backups/file/$project_alias`" = "" ]; then
				echo -e "${Red_font_prefix}$deploy_path/backups/file/$project_alias目录为空${Font_color_suffix}"
			else
				if [ "`ls -A $deploy_path/backups/file/$project_alias`" = "" ]; then
					echo -e "${Green_font_prefix}当前文件目录为空,无需临时备份${Font_color_suffix}"
				else
					echo -e "${Green_font_prefix}当前文件临时备份至$src_path/temp_file_$project_alias-$timestamp.zip${Font_color_suffix}"
					cd $deploy_path/file/$project_alias
				  zip -rq $src_path/temp_file_$project_alias-$timestamp.zip *
				fi
				
			  echo -e "${Green_font_prefix}备份文件列表:${Font_color_suffix}"
				INIT_PATH="$deploy_path/backups/file/$project_alias"
			  get_filename $INIT_PATH
			  
			  inputInfo $recover_index;
			  recover_file_index=$temp;
			  
			  if [ -z $recover_file_index ]; then
					recover_file_index=1
				fi
				
				get_filename $INIT_PATH $recover_file_index
			  
			  file_timestamp=`get_timestamp $filename`
		  
			  cd $deploy_path/file/$project_alias
		    rm -rf *
		
			  unzip -oq $deploy_path/backups/file/$project_alias/file_$project_alias-$file_timestamp.zip -d $deploy_path/file/$project_alias
			  echo -e "${Green_font_prefix}$project_alias文件恢复成功,时间戳为$file_timestamp${Font_color_suffix}"
			fi
	  fi
	
	else
		  if [ ! -d "$deploy_path/backups/deploy/$project_alias" ]; then
				echo -e "${Red_font_prefix}$deploy_path/backups/deploy/$project_alias目录不存在${Font_color_suffix}"
			elif [ "`ls -A $deploy_path/backups/deploy/$project_alias`" = "" ]; then
				echo -e "${Red_font_prefix}$deploy_path/backups/deploy/$project_alias目录为空${Font_color_suffix}"
			else
			
				inputInfo $deploy_project_alias;
	    	project_alias=$temp;
	    	
	    	if [ -z $project_alias ]; then
					printN
				elif [ ! -d "$deploy_path/backups/deploy/$project_alias" ]; then
					echo -e "${Red_font_prefix}$deploy_path/backups/deploy/$project_alias目录不存在${Font_color_suffix}"
				elif [ "`ls -A $deploy_path/backups/deploy/$project_alias`" = "" ]; then
					echo -e "${Red_font_prefix}$deploy_path/backups/deploy/$project_alias目录为空${Font_color_suffix}"
				else
					if [ "`ls -A $deploy_path/backups/deploy/$project_alias`" = "" ]; then
						echo -e "${Green_font_prefix}当前项目目录为空,无需临时备份${Font_color_suffix}"
					else
						echo -e "${Green_font_prefix}当前项目临时备份至$src_path/temp_$project_alias-$timestamp.zip${Font_color_suffix}"
						cd $deploy_path/deploy/$project_alias
					  zip -rq $src_path/temp_$project_alias-$timestamp.zip *
					fi
	    	
	    		echo -e "${Green_font_prefix}备份文件列表:${Font_color_suffix}"
					INIT_PATH="$deploy_path/backups/deploy/$project_alias"
				  get_filename $INIT_PATH
				  
				  inputInfo $recover_index;
				  recover_file_index=$temp;
				  
				  if [ -z $recover_file_index ]; then
						recover_file_index=1
					fi
					
					get_filename $INIT_PATH $recover_file_index
				  
				  file_timestamp=`get_timestamp $filename`
			  
				  cd $deploy_path/deploy/$project_alias
			    rm -rf *
			
				  unzip -oq $deploy_path/backups/deploy/$project_alias/$project_alias-$file_timestamp.zip -d $deploy_path/deploy/$project_alias
				  echo -e "${Green_font_prefix}$project_alias项目恢复成功,时间戳为$file_timestamp${Font_color_suffix}"
	    	fi
	    	
		fi
	fi
}









printInfo
 
inputInfo $input_operate_type;

operate_type=$temp;

if [ -z $operate_type ]; then
	operate_type=0
fi

while [ $operate_type -ne -1 ]

do
 #==========================查看服务器信息=======================
 if [ $operate_type -eq 0 ]; then
	
	printInfoSub
	inputInfo $input_operate_type_sub;
	operate_type_sub=$temp;
	
	if [ -z $operate_type_sub ]; then
		operate_type_sub=0
	fi
	
	
	
	if [ $operate_type_sub -eq 0 ]; then
		vmstat 1 5
	elif [ $operate_type_sub -eq 1 ]; then
		iostat -d 2 3
	elif [ $operate_type_sub -eq 2 ]; then
		uptime
	elif [ $operate_type_sub -eq 3 ]; then
		w
	elif [ $operate_type_sub -eq 4 ]; then
		last -a |head -3
	elif [ $operate_type_sub -eq 5 ]; then
		df -h | xargs | awk '{print "Free/total disk: " $11 " / " $9}'
		free -m | xargs | awk '{print "Free/total memory: " $17 " / " $8 " MB"}'
	elif [ $operate_type_sub -eq 6 ]; then
		start_log=`head -1 /var/log/messages |cut -c 1-12`
		oom=`grep -ci kill /var/log/messages`
		echo -ne "${Green_font_prefix}内存溢出情况：OOM errors since $start_log :${Font_color_suffix}" $oom	
		echo
	elif [ $operate_type_sub -eq 7 ]; then
		top -b |head -3
		echo
		top -b |head -10 |tail -4	
	elif [ $operate_type_sub -eq 8 ]; then
		ss -s
	elif [ $operate_type_sub -eq 9 ]; then
		ps auxf --width=200	
	fi
	
	
	

	
	 
		
 
 	
 fi
 #=================================================
 if [ $operate_type -eq 1 ]; then
	initPath
 fi
 #=================================================
 if [ $operate_type -eq 2 ]; then
 	deployProject
 fi
 #=================================================
 if [ $operate_type -eq 3 ]; then
 	backupProject
 fi
 #=================================================
 if [ $operate_type -eq 4 ]; then
 	recoveryProject
 fi
 #=================================================
 if [ $operate_type -eq 5 ]; then
	echo
 fi
 #=================================================
 if [ $operate_type -eq 6 ]; then
	inputInfo $input_check_uninstall_nginx;
	check_uninstall_nginx=$temp;
	if [ -z $check_uninstall_nginx ];then
		check_uninstall_nginx="y"
	fi
	#停止nginx
	pkill -9 nginx
	echo -e "${Green_font_prefix}nginx已停止 !${Font_color_suffix}"
	#删除nginx
	cd /
	rm /usr/local/nginx/ -rf
	rm /nginx -rf
	if [ $? -eq 0 ]; then
		echo -e "${Green_font_prefix}nginx卸载成功!${Font_color_suffix}"
	else
		echo -e "${Red_font_prefix}nginx卸载失败!${Font_color_suffix}"
	fi
	
 fi
 #=================================================
  if [ $operate_type -eq 7 ]; then
 	echo
 fi
 #=================================================
 if [ $operate_type -eq 8 ]; then
 	echo
 fi
 #=================================================
 if [ $operate_type -eq 9 ]; then
 	echoNowConfig
 fi
 #==========================安装jdk=======================
 if [ $operate_type -eq 10 ]; then
 	echo -e "${Green_font_prefix}======    查看是否已安装jdk    ======${Font_color_suffix}"
	yum search java | grep -i --color JDK
	
	
	inputInfo $input_check_install_jdk;
	check_install_jdk=$temp;
	if [ -z $check_install_jdk ];then
		check_install_jdk="y"
	fi
	
	if [ $check_install_jdk == "n" ]; then
		echo -e "${Green_font_prefix}取消安装jdk!!!${Font_color_suffix}"
	elif [ $check_install_jdk == "y" ]; then
		echo -e "${Green_font_prefix}======    开始安装jdk    =====${Font_color_suffix}"
		yum install java-1.8.0-openjdk  java-1.8.0-openjdk-devel
		echo -e "${Green_font_prefix}===== jdk 版本  =====${Font_color_suffix}"
		java -version
		if [ $? -eq 0 ]; then
			echo -e "${Green_font_prefix}jdk安装成功!${Font_color_suffix}"
		else
			echo -e "${Red_font_prefix}jdk安装失败!${Font_color_suffix}"
		fi
	else
		printN
	fi
	
	
	
 fi
 #==========================安装lrzsz=======================
 if [ $operate_type -eq 11 ]; then
 	yum -y install lrzsz
	if [ $? -eq 0 ]; then
		echo -e "${Green_font_prefix}RZ安装成功!${Font_color_suffix}"
	else
		echo -e "${Red_font_prefix}RZ安装失败!${Font_color_suffix}"
	fi
	
 fi
 #==========================安装gc++，zlib，pcre=======================
  if [ $operate_type -eq 12 ]; then
	yum -y install zlib zlib-devel
	if [ $? -eq 0 ]; then
		echo -e "${Green_font_prefix}zlib安装成功!${Font_color_suffix}"
	else
		echo -e "${Red_font_prefix}zlib安装失败!${Font_color_suffix}"
	fi
	yum -y install pcre pcre-devel
	if [ $? -eq 0 ]; then
		echo -e "${Green_font_prefix}pcre安装成功!${Font_color_suffix}"
	else
		echo -e "${Red_font_prefix}pcre安装失败!${Font_color_suffix}"
	fi
 	yum -y install gcc gcc-c++ autoconf automake
	if [ $? -eq 0 ]; then
		echo -e "${Green_font_prefix}gc++安装成功!${Font_color_suffix}"
	else
		echo -e "${Red_font_prefix}gc++安装失败!${Font_color_suffix}"
	fi
	
 fi
 #======================yum安装weget===========================
  if [ $operate_type -eq 13 ]; then
 	yum -y install wget
	if [ $? -eq 0 ]; then
		echo -e "${Green_font_prefix}weget安装完成 !${Font_color_suffix}"
	else
		echo -e "${Red_font_prefix}weget安装失败 !${Font_color_suffix}"
	fi
	
 fi
 #=======================安装zip和unzip==========================
  if [ $operate_type -eq 14 ]; then
 	yum install zip -y
	yum install unzip -y
	if [ $? -eq 0 ]; then
		echo -e "${Red_font_prefix}zip/unzip安装完成！！！${Font_color_suffix}"
	else
		echo -e "${Red_font_prefix}zip/unzip安装出现错误！！！${Font_color_suffix}"
	fi
	
 fi
 #==========================安装nginx=======================
 if [ $operate_type -eq 15 ]; then
	
	#确认安装
	inputInfo $input_check_install_nginx;
	check_install_nginx=$temp;
	if [ -z $check_install_nginx ];then
		check_install_nginx="y"
	fi
	
	if [ $check_install_nginx == "n" ]; then
		echo -e "${Green_font_prefix}取消安装$nginx_name!!!${Font_color_suffix}"
	elif [ $check_install_nginx == "y" ]; then
		echo -e "${Green_font_prefix}开始安装$nginx_name!!!${Font_color_suffix}"
		#检测nginx是否已经安装
		if [ ! -d "/usr/local/nginx/" ]; then
			if [ ! -d "/nginx/" ];then
				echo -e "${Green_font_prefix}创建$nginx_name安装目录...${Font_color_suffix}"
				mkdir /nginx
				installNginx		
			else
			   installNginx
			fi
		else
			echo -e "${Red_font_prefix}检测到$nginx_name已经安装,安装目录: /usr/local/nginx/ !${Font_color_suffix}"
		fi	
	else
		printN
	fi
	
 
 	
 fi
 #==========================启动nginx/停止nginx=======================
  if [ $operate_type -eq 16 ]; then
	
	inputInfo $input_nginx_start_flag;
	nginx_start_flag=$temp;
	if [ -z $nginx_start_flag ];then
		nginx_start_flag=0
	fi
	
	#0启动
	if [ $nginx_start_flag -eq 0 ]; then
		/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
		if [ $? -eq 0 ]; then
			echo -e "${Green_font_prefix}nginx启动成功--使用配置文件:/usr/local/nginx/conf/nginx.conf !${Font_color_suffix}"
		else
			echo -e "${Red_font_prefix}nginx启动出现问题！！！！!${Font_color_suffix}"
		fi
	else
		pkill -9 nginx
		echo -e "${Green_font_prefix}nginx已停止 !${Font_color_suffix}"
	fi

 fi
 #=====================一键替换nginx配置文件============================
 if [ $operate_type -eq 17 ]; then
	echo -e "${Green_font_prefix}提示：替换前先将 nginx.conf 文件传到服务器的 $src_path 目录${Font_color_suffix}"
	inputInfo $input_nginx_conf;
	nginx_conf=$temp;
	if [ -z $nginx_conf ];then
		nginx_conf="y"
	fi
	
	if [ $nginx_conf == "y" ];then
		#停止nginx服务
		pkill -9 nginx
		echo -e "${Green_font_prefix}nginx已停止 !${Font_color_suffix}"
		#检测待替换的配置文件是否上传
		 if [ ! -f "$src_path/nginx.conf" ]; then
			echo -e "${Red_font_prefix}替换失败！！！nginx.conf文件不存在$src_path 目录!!!${Font_color_suffix}"	
		 else
			#备份原配置
			$timestamp=`date "+%Y%m%d%H%M%S"`
			cd /usr/local/nginx/conf/
			cp nginx.conf nginx_backup_$timestamp.conf
			echo -e "${Green_font_prefix}nginx配置文件已备份：备份文件名: nginx_backup_$timestamp.conf !${Font_color_suffix}"
			#删除原配置
			rm nginx.conf -f
			if [ $? -eq 0 ]; then
				echo -e "${Green_font_prefix}删除老nginx配置文件...${Font_color_suffix}"
			else
				echo -e "${Red_font_prefix}删除老nginx配置文件出错...${Font_color_suffix}"
			fi			
			#复制新配置文件
			cp $src_path/nginx.conf nginx.conf
			if [ $? -eq 0 ]; then
				echo -e "${Green_font_prefix}复制新nginx配置文件...${Font_color_suffix}"
			else
				echo -e "${Red_font_prefix}复制新nginx配置文件出错...${Font_color_suffix}"
			fi	
			#启动nginx
			/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
			if [ $? -eq 0 ]; then
				echo -e "${Green_font_prefix}nginx启动成功--使用配置文件:/usr/local/nginx/conf/nginx.conf !${Font_color_suffix}"
			else
				echo -e "${Red_font_prefix}nginx启动出现问题！！！！!${Font_color_suffix}"
			fi
	     fi
			
	else
	    echo -e "${Green_font_prefix}取消替换nginx配置文件...${Font_color_suffix}"
	fi
	
 	
 fi
 #==========================开放端口=======================
 if [ $operate_type -eq 18 ]; then
	echo -e "${Green_font_prefix}当前已开放端口如下:${Font_color_suffix}"
	/sbin/iptables -L -n --line-number
 	inputInfo $input_port_num;
	port_num=$temp;
	
	if [ $port_num == "n" ];then
		delport
		echo -e "${Green_font_prefix}取消设置端口...${Font_color_suffix}"	
	else
	    /sbin/iptables -I INPUT -p tcp --dport $port_num -j ACCEPT
		/etc/rc.d/init.d/iptables save
		/etc/init.d/iptables restart
		/sbin/iptables -L -n --line-number
		if [ $? -eq 0 ]; then
			echo -e "${Green_font_prefix}端口设置成功 !${Font_color_suffix}"
		else
			echo -e "${Red_font_prefix}端口设置失败 !${Font_color_suffix}"
		fi
		
		delport
	fi
	
	
 fi
 #==========================启动spring boot项目=======================
 if [ $operate_type -eq 19 ]; then
 	inputInfo $input_spring_boot;
	spring_boot=$temp;
	
	RESOURCE_NAME=spring_boot
 
	tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
	if [ ${tpid} ]; then
	echo 'Stop Process...'
	kill -15 $tpid
	fi
	sleep 5
	tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
	if [ ${tpid} ]; then
	echo 'Kill Process!'
	kill -9 $tpid
	else
	echo 'Stop Success!'
	fi
	 
	tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
	if [ ${tpid} ]; then
		echo 'App is running.'
	else
		echo 'App is NOT running.'
	fi
	 
	rm -f tpid
	nohup java -jar ./$RESOURCE_NAME --spring.profiles.active=test &
	echo $! > tpid
	if [ $? -eq 0 ]; then
		echo -e "${Green_font_prefix}项目$RESOURCE_NAME启动成功 !${Font_color_suffix}"
	else
		echo -e "${Red_font_prefix}项目$RESOURCE_NAME启动失败 !${Font_color_suffix}"
	fi
	
 fi
 

 #==========================一键安装tomcat=======================
 if [ $operate_type -eq 20 ]; then
	inputInfo $input_check_install_tomcat;
	check_install_tomcat=$temp;
	if [ -z $check_install_tomcat ];then
		check_install_tomcat="y"
	fi
	
	if [ $check_install_tomcat == "n" ]; then
		echo -e "${Green_font_prefix}取消安装tomcat!!!${Font_color_suffix}"
	elif [ $check_install_tomcat == "y" ]; then
		echo -e "${Green_font_prefix}开始安装tomcat!!!${Font_color_suffix}"
		#检测tomcat是否已经安装
		if [ ! -d "/tomcat$tomcat_version" ]; then
			if [ ! -d "/tomcat$tomcat_version" ];then
				echo -e "${Green_font_prefix}创建tomcat$tomcat_version安装目录...${Font_color_suffix}"
				mkdir /tomcat$tomcat_version
				installTomcat
			else
				installTomcat
			fi
			if [ $? -eq 0 ]; then
				echo -e "${Green_font_prefix}tomcat$tomcat_version安装完成 !${Font_color_suffix}"
			else
				echo -e "${Red_font_prefix}tomcat$tomcat_version安装失败 !${Font_color_suffix}"
			fi
		else
			echo -e "${Red_font_prefix}检测到tomcat已经安装!${Font_color_suffix}"
		fi	
	else
		printN
	fi

	
 fi
 #==========================启动或停止tomcat=======================
 if [ $operate_type -eq 21 ]; then
	echo -e "${Green_font_prefix}当前tomcat启动状态 :${Font_color_suffix}"
	ps aux |grep tomcat
	inputInfo $input_tomcat_flag;
	tomcat_flag=$temp;
	if [ -z $tomcat_flag ];then
		tomcat_flag=1
	fi
	
	
	if [ $tomcat_flag -eq 1 ];then
		cd /tomcat$tomcat_version/$tomcat_name/bin
		./startup.sh 
		echo -e "${Green_font_prefix}Tomcat$tomcat_version已启动.${Font_color_suffix}"
	elif [ $tomcat_flag -eq 0 ];then
	    cd /tomcat$tomcat_version/$tomcat_name/bin
		./shutdown.sh  
		echo -e "${Green_font_prefix}tomcat$tomcat_version已停止.${Font_color_suffix}"		
	else 
		printN
	fi
	
 	
 fi
 #==========================查看tomcat运行状态以及强制关闭=======================
 if [ $operate_type -eq 22 ]; then
    echo -e "${Green_font_prefix}Tomcat运行状态如下：${Font_color_suffix}"
	ps aux |grep tomcat
	echo -e "${Green_font_prefix}Tomcat是否关闭：${Font_color_suffix}"
	ps -ef|grep java
	
	inputInfo $input_kill_port;
	kill_port=$temp;
	
	
	if [ $kill_port -eq 0 ];then 
		echo -e "${Green_font_prefix}取消强制杀死进程${Font_color_suffix}"
	else
	    kill -9 $kill_port
		echo -e "${Red_font_prefix}Tomcat强制关闭${Font_color_suffix}"		
	fi
	
 	
 fi
 #==========================查看tomcat日志=======================
 if [ $operate_type -eq 23 ]; then
 	tail -f /tomcat$tomcat_version/$tomcat_name/logs/catalina.out
	
 fi
  #==========================卸载tomcat=======================
 if [ $operate_type -eq 24 ]; then
	inputInfo $input_check_uninstall_tomcat;
	check_uninstall_tomcat=$temp;
	if [ -z $check_uninstall_tomcat ];then
		check_uninstall_tomcat="y"
	fi
	
	if [ $check_uninstall_tomcat == "n" ]; then
		echo -e "${Green_font_prefix}取消卸载tomcat!!!${Font_color_suffix}"
	elif [ $check_uninstall_tomcat == "y" ]; then
		echo -e "${Green_font_prefix}开始卸载tomcat!!!${Font_color_suffix}"
		cd /tomcat$tomcat_version/$tomcat_name/bin
		./shutdown.sh
		echo -e "${Green_font_prefix}tomcat已停止!!!${Font_color_suffix}"
		cd /
		rm /tomcat$tomcat_version -rf
		if [ $? -eq 0 ]; then
			echo -e "${Green_font_prefix}tomcat$tomcat_version卸载完成 !${Font_color_suffix}"
		else
			echo -e "${Red_font_prefix}tomcat$tomcat_version卸载失败 !${Font_color_suffix}"
		fi
	else
		printN
	fi
	
	
 fi
  #======================一键替换server.xml配置文件===========================
 if [ $operate_type -eq 25 ]; then
 	echo -e "${Green_font_prefix}提示：替换前先将 server.xml 文件传到服务器的 $src_path 目录${Font_color_suffix}"
	inputInfo $input_tomcat_conf;
	tomcat_conf=$temp;
	if [ -z $tomcat_conf ];then
		tomcat_conf="y"
	fi
	
	if [ $tomcat_conf == "y" ];then
		#停止tomcat服务
		cd /tomcat$tomcat_version/$tomcat_name/bin
		./shutdown.sh  
		echo -e "${Green_font_prefix}tomcat$tomcat_version已停止.${Font_color_suffix}"	
		#检测待替换的配置文件是否上传
		 if [ ! -f "$src_path/server.xml" ]; then
			echo -e "${Red_font_prefix}替换失败！！！server.xml文件不存在$src_path 目录!!!${Font_color_suffix}"	
		 else
			#备份原配置
			$timestamp=`date "+%Y%m%d%H%M%S"`
			cd /tomcat$tomcat_version/$tomcat_name/conf
			cp server.xml server_backup_$timestamp.xml
			echo -e "${Green_font_prefix}tomcat配置文件已备份：备份文件名: server_backup_$timestamp.xml !${Font_color_suffix}"
			#删除原配置
			rm server.xml -f
			if [ $? -eq 0 ]; then
				echo -e "${Green_font_prefix}删除老tomcat配置文件...${Font_color_suffix}"
			else
				echo -e "${Red_font_prefix}删除老tomcat配置文件出错...${Font_color_suffix}"
			fi			
			#复制新配置文件
			cp $src_path/server.xml server.xml
			if [ $? -eq 0 ]; then
				echo -e "${Green_font_prefix}复制新tomcat配置文件...${Font_color_suffix}"
			else
				echo -e "${Red_font_prefix}复制新tomcat配置文件出错...${Font_color_suffix}"
			fi	
			#启动tomcat
			cd /tomcat$tomcat_version/$tomcat_name/bin
			./startup.sh 
			
			if [ $? -eq 0 ]; then
				echo -e "${Green_font_prefix}Tomcat$tomcat_version已启动.${Font_color_suffix}"
			else
				echo -e "${Red_font_prefix}Tomcat$tomcat_version启动出现问题！！！！!${Font_color_suffix}"
			fi
	     fi
			
	else
	    echo -e "${Green_font_prefix}取消替换server.xml配置文件...${Font_color_suffix}"
	fi
	
 fi
 
 #==========================安装中文环境=======================
 if [ $operate_type -eq 26 ]; then
 	yum groupinstall chinese-support
	LANG="Zn_CN.UTF-8"
	if [ $? -eq 0 ]; then
		echo -e "${Green_font_prefix}设置中文完毕...${Font_color_suffix}"
	else
		echo -e "${Red_font_prefix}设置中文出错...${Font_color_suffix}"
	fi
	
 fi
 #=================================================
  if [ $operate_type -eq 27 ]; then
 	echo
 fi
 #==========================安装SSR=======================
 if [ $operate_type -eq 28 ]; then
 	inputInfo $input_install_type;
	install_type=$temp;
	if [ -z $install_type ];then
		install_type=0
	fi
	if [ $install_type -eq 1 ]; then
		inputInfo $input_backup_type;
		backup_type=$temp;
		if [ $backup_type == "n" ]; then
			wget -N --no-check-certificate $ssr_multi_url && chmod +x ssrmu.sh && bash ssrmu.sh
		elif [ $backup_type == "y" ]; then
			wget -N --no-check-certificate $ssr_multi_backup_url && chmod +x ssrmu.sh && bash ssrmu.sh
		else
			printN
		fi
		echo -e "${Green_font_prefix}SSR多用户安装成功,管理命令 : bash ssrmu.sh${Font_color_suffix}"
	elif [ $install_type -eq 0 ]; then
		inputInfo $input_backup_type;
		backup_type=$temp;
		if [ -z $backup_type ];then
			backup_type="n"
		fi
		if [ $backup_type == "n" ]; then
			yum -y install wget
			wget -N --no-check-certificate $ssr_simple_url && chmod +x ssr.sh && bash ssr.sh
		elif [ $backup_type == "y" ]; then
			yum -y install wget
			wget -N --no-check-certificate $ssr_simple_backup_url && chmod +x ssr.sh && bash ssr.sh
		else
			printN
		fi
		echo -e "${Green_font_prefix}SSR单用户安装成功,管理命令 : bash ssr.sh${Font_color_suffix}"
	else
		printN
	fi
 fi
 
 
 #==========================安装谷歌BBR加速=======================
  if [ $operate_type -eq 29 ]; then
	inputInfo $input_bbrcheck_type;
	bbrcheck_type=$temp;
	if [ -z $bbrcheck_type ];then
		bbrcheck_type="y"
	fi
	if [ $bbrcheck_type == "n" ]; then
		yum -y install wget
		wget --no-check-certificate $ssr_bbr_url
		chmod +x bbr.sh
		./bbr.sh
	elif [ $bbrcheck_type == "y" ]; then
		bbrflag=`lsmod | grep bbr`
		if [ $centos_version == "tcp_bbr" ]; then
			echo -e "${Green_font_prefix}bbr已安装并启动成功!${Font_color_suffix}"
		else
			echo -e "${Red_font_prefix}bbr未安装或启动失败!${Font_color_suffix}"
		fi
	else
		printN
	fi
 fi
 
 
 #==========================一键安装mysql=======================
 if [ $operate_type -eq 30 ]; then
	inputInfo $input_check_install_mysql;
	check_install_mysql=$temp;
	if [ -z $check_install_mysql ];then
		check_install_mysql="y"
	fi
	
	if [ $check_install_mysql == "n" ]; then
		echo -e "${Green_font_prefix}取消安装mysql!${Font_color_suffix}"
	elif [ $check_install_mysql == "y" ]; then
		#获取centos版本
	centos_version=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`
	echo -e "${Yello_font_prefix}当前centos版本：$centos_version${Font_color_suffix}"
	if [ $centos_version == "7" ]; then
		echo -e "${Yello_font_prefix}开始执行centos：$centos_version的安装${Font_color_suffix}"
		cd /home;
		wget $mysql_7_rpm
		yum localinstall $mysql_7_rpm_name -y
	elif [ $centos_version == "6" ]; then
		echo -e "${Blue_font_prefix}开始执行centos：$centos_version的安装${Font_color_suffix}"
		cd /home;
		wget $mysql_6_rpm
		yum localinstall $mysql_6_rpm_name -y
	fi
	
	yum install mysql-server -y

	mysqld --initialize --user=mysql

	#初始化数据库
	service mysqld start
	sleep 1
	defaultmysqlpwd=`grep 'A temporary password' /var/log/mysqld.log | awk -F"root@localhost: " '{ print $2}' `
	echo -e "${Pink_font_prefix}mysql默认密码：$defaultmysqlpwd${Font_color_suffix}"
	/usr/bin/mysql -uroot -p${defaultmysqlpwd} <<EOF
	set global validate_password_policy=0;
	SET PASSWORD = PASSWORD('$mysql_pwd');
	grant all privileges on *.* to 'root'@'%' identified by 'root';
	update user set host='%' where user='root';
	flush privileges;
EOF
	sleep 1
	service mysqld restart
	echo -e "${Yello_font_prefix}==================mysql安装信息====================${Font_color_suffix}"
	echo 
	echo -e "${Yello_font_prefix}数据库安装完毕...当前用户名:root密码:$mysql_pwd${Font_color_suffix}"
	echo -e "${Yello_font_prefix}默认开启公网访问...$mysql_pwd${Font_color_suffix}"
	echo 
	echo -e "${Yello_font_prefix}==================mysql安装信息=====================${Font_color_suffix}"
	else
		printN
	fi
	
	
	
 fi
 
 #==========================一键卸载mysql=======================
 if [ $operate_type -eq 31 ]; then
	inputInfo $input_uninstall_type;
	uninstall_type=$temp;
	if [ -z $uninstall_type ];then
		uninstall_type="y"
	fi	
	if [ $uninstall_type == "y" ]; then
		yum remove mysql mysql-server mysql-libs compat-mysql51 -y
		if [ $? -eq 0 ]; then
			echo -e "${Green_font_prefix}mysql卸载完成！！！${Font_color_suffix}"
		else
			echo -e "${Red_font_prefix}mysql卸载失败！！！${Font_color_suffix}"
		fi
	elif [ $uninstall_type == "y" ]; then
		echo -e "${Green_font_prefix}取消卸载mysql！！！${Font_color_suffix}"
	else
		printN
	fi
 fi
 
 #==========================启动或停止mysql=======================
 if [ $operate_type -eq 32 ]; then
	echo -e "${Green_font_prefix}mysql安装路径:${Font_color_suffix}"
	which mysql
	
	inputInfo $input_open_mysql_flag;
	open_mysql_flag=$temp;
	if [ -z $open_mysql_flag ];then
		open_mysql_flag=2
	fi
	if [ $open_mysql_flag -eq 1 ]; then
		service mysqld stop
		if [ $? -eq 0 ]; then
			echo -e "${Green_font_prefix}mysql停止成功！！！${Font_color_suffix}"
		else
			echo -e "${Red_font_prefix}mysql停止出错！！！${Font_color_suffix}"
		fi
	elif [ $open_mysql_flag -eq 0 ]; then
		service mysqld start
		if [ $? -eq 0 ]; then
			echo -e "${Green_font_prefix}mysql启动成功！！！${Font_color_suffix}"
		else
			echo -e "${Red_font_prefix}mysql启动出错！！！${Font_color_suffix}"
		fi
	elif [ $open_mysql_flag -eq 2 ]; then
		service mysqld restart	
		if [ $? -eq 0 ]; then
			echo -e "${Green_font_prefix}mysql重启成功！！！${Font_color_suffix}"
		else
			echo -e "${Red_font_prefix}mysql重启出错！！！${Font_color_suffix}"
		fi
	else
		printN
	fi
 fi
 #==========================修改mysql密码=======================
 if [ $operate_type -eq 33 ]; then
	inputInfo $input_mysql_now_pwd;
	mysql_now_pwd=$temp;
	
	inputInfo $input_mysql_new_pwd;
	mysql_new_pwd=$temp;
	
	echo -e "${Yello_font_prefix}开始将密码:$mysql_now_pwd修改为:$mysql_new_pwd${Font_color_suffix}"
	
	/usr/bin/mysql -uroot -p$mysql_now_pwd <<EOF
	SET PASSWORD = PASSWORD('$mysql_new_pwd');
EOF
	if [ $? -eq 0 ]; then
		echo -e "${Yello_font_prefix}密码修改完成...${Font_color_suffix}"
	else
		echo -e "${Red_font_prefix}当前密码输入出错...${Font_color_suffix}"
	fi
	
 fi
  #==========================备份mysql数据库=======================
   if [ $operate_type -eq 34 ]; then
	echo -e "${Green_font_prefix}当前配置的mysql用户名:$db_mysql_user 密码:$db_mysql_password ${Font_color_suffix}"
	
	echo -e "${Red_font_prefix}开始执行数据库备份...${Font_color_suffix}"
	
	inputInfo $input_database_name;
	database_name=$temp;
	if [ ! -z $database_name ]; then
		if [ ! -d "$base_path/backups/db/$database_name" ]; then
			mkdir -p $base_path/backups/db/$database_name			
			if [ ! -d "$base_path/backups/db/$database_name/$yearmonth" ]; then
				 mkdir -p $base_path/backups/db/$database_name/$yearmonth
			fi
		fi
		
		mysqldump -u$db_mysql_user -p$db_mysql_password $database_name --hex-blob > $base_path/backups/db/$database_name/$yearmonth/$database_name-$timestamp.sql
		if [ $? -eq 0 ]; then
			echo -e "${Green_font_prefix}mysql数据库:$database_name备份完成...${Font_color_suffix}"
			echo -e "${Green_font_prefix}备份路径:$base_path/backups/db/$database_name/$yearmonth/${Font_color_suffix}"
			
			
			inputInfo $input_database_download;
			database_download=$temp;
			if [ $database_download == "n" ]; then
				echo -e "${Green_font_prefix}退出备份....${Font_color_suffix}"
			elif [ $database_download == "y" ]; then
				cd $base_path/backups/db/$database_name/$yearmonth/
				sz $database_name-$timestamp.sql
				if [ $? -eq 0 ]; then
					echo -e "${Green_font_prefix}下载完成,默认下载路径为windows用户下Download目录！！！${Font_color_suffix}"
				else
					echo -e "${Red_font_prefix}下载失败,需要安装SZ！！！${Font_color_suffix}"
				fi
			else
				printN
			fi
			
		else
			echo -e "${Red_font_prefix}mysql数据库:$database_name备份出错...${Font_color_suffix}"
		fi
		
	else
		echo -e "${Red_font_prefix}请输入mysql数据库名称...${Font_color_suffix}"
	fi
	
	
 fi
 #==========================一键执行mysql脚本=======================
 if [ $operate_type -eq 35 ]; then
	echo -e "${Green_font_prefix}提示：执行前先将 **.sql 文件传到服务器的 $src_path 目录${Font_color_suffix}"
	inputInfo $input_sql_name;
	sql_name=$temp;
	
	inputInfo $input_sql_insert_flag;
	sql_insert_flag=$temp;
	
	if [ -z $sql_insert_flag ];then
		sql_insert_flag="n"
	fi
	
	if [ $sql_insert_flag == "y" ];then
		#执行数据库导入
		echo -e "${Green_font_prefix}开始执行数据库$sql_name导入...${Font_color_suffix}"
		/usr/bin/mysql -uroot -p$db_mysql_password <<EOF
		use $sql_name;
	    source $src_path/$sql_name.sql;
EOF
		if [ $? -eq 0 ]; then
			echo -e "${Green_font_prefix}数据库$sql_name导入完成...${Font_color_suffix}"
		else
			echo -e "${Red_font_prefix}数据库$sql_name导入出错,清检查脚本数据库密码配置...${Font_color_suffix}"
		fi
		
	else
		mysql -uroot -p$db_mysql_password < $src_path/$sql_name.sql --default-character-set=utf8
		if [ $? -eq 0 ]; then
			echo -e "${Green_font_prefix}脚本$src_path/$sql_name.sql执行完成！！！${Font_color_suffix}"
		else
			echo -e "${Red_font_prefix}脚本$src_path/$sql_name.sql执行出现错误！！！${Font_color_suffix}"
		fi
	fi
	
 fi
 
 
 
 
 
 
 
 
 
 
 
 ############################################分割线#########################################################
 
 inputInfo $input_init_menu;
 init_menu=$temp;
 if [ -z $init_menu ];then
	init_menu="n"
 fi
 if [ $init_menu == "y" ]; then
	#重新显示菜单
	printInfo
 fi
 
	
 inputInfo $input_operate_type;
 operate_type=$temp;
 if [ -z $operate_type ]; then
	operate_type=0
 fi
 
done